home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / ctrlalt.zip / RELEASE.ASM < prev    next >
Assembly Source File  |  1986-04-17  |  5KB  |  93 lines

  1. title  RELEASE by R.M.Wilson
  2. cseg segment
  3.          org 100H
  4.          assume  cs:cseg, ds:cseg
  5. com_file_length =  200H + offset absolute_zero - offset com_file_code
  6.  
  7. entry:   mov ax,cs                    ;Store the current code segment less 18 
  8.          sub ax,18                    ;in a certain spot in what will 
  9.          mov lowest_seg[2],ax         ;become a separate com-file.
  10.          xor si,si
  11.          mov ds,si                    ;Point ds:si to 0000:0000 and
  12.          mov cx,200H                  ;copy the first 512 bytes 
  13.          mov di,offset absolute_zero  ;(the current interrupt vectors)
  14.          rep movsb                    ;to a place in the com-file.
  15.          push cs                      
  16.          pop ds                       ;Restore ds.
  17.          mov si,81H                   
  18. look_for_filename:                    ;Locate the proposed com-file 
  19.          lodsb                        ;name on the command line.
  20.          cmp al,' '
  21.          je look_for_filename
  22.          dec si                       ;Remember where it starts (in dx)
  23.          mov dx,si                    ;for later DOS call.
  24. look_for_end:
  25.          lodsb
  26.          cmp al,' '
  27.          je found_end_of_filename
  28.          cmp al,0DH
  29.          jne look_for_end
  30. found_end_of_filename:
  31.          mov word ptr ds:[si-1],'c.'
  32.          mov word ptr ds:[si+1],'mo'  ;Add '.com' and an ASCII 0
  33.          mov byte ptr ds:[si+3],0     ;to the end of the filename.
  34.          mov ah,3CH
  35.          mov cx,20H
  36.          int 21H                      ;Call DOS to open com-file. 
  37.          jc error                     ;(Beep if unable to open.) 
  38.          mov bx,ax                    ;Otherwise, move the file handle to bx
  39.          mov ah,40H                   ;and get ready to write.
  40.          mov dx,offset com_file_code
  41.          mov cx,com_file_length
  42.          int 21H                      ;Call DOS to write com-file, and exit. 
  43.          mov ah,3EH
  44.          int 21H
  45.          ret
  46.  
  47. error:   mov ax,0E07H                 
  48.          int 10H                      ;Beep if necessary.
  49.          ret
  50. ;--------------------------------------------------------------------------
  51. adjusted_offset = 100H + offset absolute_zero - offset com_file_code
  52. com_file_code: 
  53.          xor di,di                    ;Point es:di to 0000:0000.
  54.          mov es,di
  55.          mov si,adjusted_offset       ;Point ds:si to stored vectors.
  56.          mov cx,0200H                 
  57.          cli                          ;Disable interrupts and
  58.          repz movsb                   ;copy the original interrupt vectors
  59.          sti                          ;over the current ones.
  60.          mov dx,cs
  61. return_memory:        
  62.          mov es,dx                    ;Ask DOS to return allocated memory
  63.          mov ah,49H                   ;at segment es (when es is 1 +
  64.          int 21H                      ;the segment of a MCB).
  65.          dec dx
  66. search:  dec dx                       ;Look for MCB's (Memory Control Blocks).
  67.     lowest_seg label word             ;Don't go too low....
  68.          cmp dx,9999H                 ;(9999 will have been replaced by 
  69.          jbe fini                     ;the original segment less 18.) 
  70.          mov ds,dx
  71.          cmp byte ptr ds:[0000],'M'   ;Every MCB (except the last) starts 
  72.          jne search                   ;with an 'M'; save time by only asking
  73.          inc dx                       ;DOS to return memory when 'M' is there.
  74.          jmp return_memory            ;(No harm is done by asking DOS to
  75.     fini:ret                          ;return memory if none was allocated.)
  76.  
  77.          absolute_zero label byte     ;Store original interrupt vectors 
  78.                                       ;here.
  79. cseg ends
  80. end entry
  81.  
  82.  
  83. Technical note:  The number 18 is subtracted from the code segment because the
  84. '.com' file created by RELEASE tries to release the memory DOS has allocated
  85. for the copy of the environment for, and perhaps a batch file used for the
  86. loading of, resident programs.  These lie at segments below the code segment
  87. when RELEASE is run.  The number 18 should suffice unless the user has an
  88. environment significantly larger than the 10 16-byte paragraphs DOS normally
  89. allows.  If it is replaced by a larger number, there is danger that the RELEASE
  90. files may disallocate memory used by an extremely tiny resident program loaded
  91. just before RELEASE is run.  I would keep it small; then the worst that can
  92. happen is that a few paragraphs of memory would not be returned.
  93.